package com.example.kx024;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

/**
 *  单选框
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       Button button = findViewById(R.id.button);
       RadioGroup radioGroup = findViewById(R.id.rg);

       button.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
               RadioButton radioButton = findViewById(checkedRadioButtonId);

               if (radioButton.getText().equals("B:100")){
                   Toast.makeText(MainActivity.this, "回答正确", Toast.LENGTH_SHORT).show();
               }else {
                   AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                   builder.setMessage("嘻嘻嘻嘻嘻嘻嘻嘻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻寻");
                   builder.setPositiveButton("确定",null);
                   builder.show();
               }


           }
       });

    }
}